//
//  UserInputIsValid.m
//  JRWD
//
//  Created by user on 16/2/27.
//  Copyright © 2016年 hejin. All rights reserved.
//

#import "UserInputIsValid.h"

@implementation UserInputIsValid

//验证手机号
+ (BOOL)phoneIsValid:(NSString *)phoneNumber {
    
    //验证手机号 11位数字
//    NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
//    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
//    
//    NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
//    
//    NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
    

//    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
//    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
//    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];

//    BOOL res2 = [regextestcm evaluateWithObject:phoneNumber];
//    BOOL res3 = [regextestcu evaluateWithObject:phoneNumber];
//    BOOL res4 = [regextestct evaluateWithObject:phoneNumber];
    
//    if (res1 || res2 || res3 || res4 ) {
//        return YES;
//    } else {
//        return NO;
//    }
    
    NSString * MOBILE = @"^\\d{11}$";
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    BOOL res1 = [regextestmobile evaluateWithObject:phoneNumber];
    return res1;
//    return YES;
}

+ (BOOL)validateIdentityCard:(NSString *)identityCard
{    
    BOOL flag;
    if (identityCard.length <= 0) {
        flag = NO;
        return flag;
    }
    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    return [identityCardPredicate evaluateWithObject:identityCard];
    return YES;
}



@end
